cmake_minimum_required(VERSION 3.5.0)
project(VideoModuleApp VERSION 1.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++17 -Wl,-rpath=./:./lib")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

enable_language(CUDA)

# 设定编译架构和标准
set(CMAKE_CUDA_ARCHITECTURES 86)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)


if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# Debug 配置
message(STATUS "CMAKE_BUILD_TYPE Debug")

elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
message(STATUS "CMAKE_BUILD_TYPE Release")
# Release 配置
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall -s")
endif()

set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release/${CMAKE_BUILD_TYPE})
set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})

find_package(PkgConfig REQUIRED QUIET)
find_package(CUDA REQUIRED)

get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
    if (_variableName MATCHES "CUDA")
        message(STATUS "${_variableName} = ${${_variableName}}")
    endif()
endforeach()
# find_package(CUDAToolkit REQUIRED)

if(CUDA_FOUND)
    message(STATUS "CUDA工具包已找到: ${CUDA_TOOLKIT_ROOT_DIR}")
    include_directories(${CUDA_INCLUDE_DIRS})
    
    # 添加CUDA运行时库
    link_libraries(${CUDA_LIBRARIES})
    
    # 可选：指定CUDA架构（根据你的GPU调整）
    set(CMAKE_CUDA_ARCHITECTURES 75)  # 例如：GTX 1660为75，RTX 30系列为86
endif()


set(CUDA_ARCH_LIST "6.0;6.1;7.0;7.5;8.0;8.3")  # 根据GPU架构调整
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -g -G)  # 调试选项
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -std=c++11)  # C++标准

pkg_search_module(AvUtil REQUIRED libavutil IMPORTED_TARGET)
pkg_search_module(AvCodec REQUIRED libavcodec IMPORTED_TARGET)
pkg_search_module(AvFilter REQUIRED libavfilter IMPORTED_TARGET)
pkg_search_module(AvDevice REQUIRED libavdevice IMPORTED_TARGET)
pkg_search_module(AvFormat REQUIRED libavformat IMPORTED_TARGET)
pkg_search_module(SwScale REQUIRED libswscale IMPORTED_TARGET)
pkg_search_module(SwResample REQUIRED libswresample IMPORTED_TARGET)

# include_directories(BEFORE SYSTEM /usr/local/include)
# link_directories(/usr/local/lib)

include_directories(${CMAKE_SOURCE_DIR}/submodule/ZLToolKit/src)
include_directories(${CMAKE_SOURCE_DIR}/submodule/json/single_include)
include_directories(${CMAKE_SOURCE_DIR}/submodule/spdlog/include)


if(TARGET PkgConfig::AvCodec)
  message(STATUS "Found AvCodec : ${AvCodec_LINK_LIBRARIES}")
  message(STATUS "Found AvCodec : ${AvCodec_INCLUDE_DIRS}")
else()
  message(STATUS "NotFound AvCodec")
endif()



if(TARGET PkgConfig::AvUtil)
  message(STATUS "Found AvUtil : ${AvUtil_LINK_LIBRARIES}")
  message(STATUS "Found AvUtil : ${AvUtil_INCLUDE_DIRS}")
else()
  message(STATUS "NotFound AvUtil")
endif()


find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "${OpenCV_INCLUDE_DIRS}")

# add_definitions(-DSTB_IMAGE_WRITE_IMPLEMENTATION)
# include_directories(${CMAKE_SOURCE_DIR}/stb)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")


add_definitions(-DHWACCELS_NVIDIA)

add_subdirectory(submodule)
add_subdirectory(src)
